package tabdulin.sms.visual;

import java.awt.Dimension;
import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javax.swing.JDialog;

import tabdulin.sms.contacts.Contact;
import java.awt.Font;

/**
 * @author Talgat Abdulin
 *
 */
@SuppressWarnings("serial")
public class ContactNameDialog extends JDialog {
    private JPanel contentPane = null;
    private SmsSenderFrame owner;
    private JLabel contactNameLabel;
    private JButton addButton;
    private JButton cancelButton;
    private JTextField nameTextField;
    
    private ContactsDialog contactsDialog;
    
    /**
     * @param owner
     */
    public ContactNameDialog(SmsSenderFrame owner, ContactsDialog contactsDialog) {
        super(owner);
        this.owner = owner;
        this.contactsDialog = contactsDialog;
        initialize();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        setLocation(this.owner.getX() + this.owner.getWidth(), this.owner.getY());
        setTitle("Добавление нового контакта");
        setSize(new Dimension(366, 112));
        setModal(true);
        setContentPane(getContactContentPane());
    }

    /**
     * This method initializes jContentPane
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getContactContentPane() {
        if (contentPane == null) {
            contentPane = new JPanel();
            contentPane.setLayout(null);
            contentPane.add(getAddContactNameLabel(), null);
            contentPane.add(getNameTextField(), null);
            contentPane.add(getAddButton(), null);
            contentPane.add(cancelButton(), null);
        }
        return contentPane;
    }

    
    /**
     * This method initializes contactNameTextField 
     *  
     * @return javax.swing.JTextField   
     */
    private JTextField getNameTextField() {
        if (nameTextField == null) {
            nameTextField = new JTextField();
            nameTextField.setBounds(new Rectangle(9, 28, 339, 24));
            nameTextField.setFont(new Font("UnDotum", Font.PLAIN, 12));
        }
        return nameTextField;
    }
    
    /**
     * This method initializes addContactNameLabel  
     *  
     * @return javax.swing.JLabel   
     */
    private JLabel getAddContactNameLabel() {
        if (contactNameLabel == null) {
            contactNameLabel = new JLabel();
            contactNameLabel.setText("Введите имя контакта");
            contactNameLabel.setFont(new Font("UnDotum", Font.BOLD, 12));
            contactNameLabel.setBounds(new Rectangle(8, 7, 339, 22));
        }
        return contactNameLabel;
    }
    
    /**
     * This method initializes addContactNameOKButton   
     *  
     * @return javax.swing.JButton  
     */
    private JButton getAddButton() {
        if (addButton == null) {
            addButton = new JButton();
            addButton.setBounds(new Rectangle(10, 57, 138, 21));
            addButton.setFont(new Font("UnDotum", Font.BOLD, 12));
            addButton.setText("Добавить");
            addButton.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent e) {
                    Contact contact = new Contact();
                    contact.setOperator(owner.getOperator());
                    contact.setPrefix(owner.getPrefix());
                    contact.setNumber(owner.getNumber());
                    contact.setName(nameTextField.getText());
                    contactsDialog.addContact(contact);
                    nameTextField.setText(null);
                    ContactNameDialog.this.setVisible(false);
                }
            });
        }
        return addButton;
    }
    
    /**
     * This method initializes addContactNameCancelButton   
     *  
     * @return javax.swing.JButton  
     */
    private JButton cancelButton() {
        if (cancelButton == null) {
            cancelButton = new JButton();
            cancelButton.setBounds(new Rectangle(183, 57, 162, 21));
            cancelButton.setFont(new Font("UnDotum", Font.BOLD, 12));
            cancelButton.setText("Отменить");
            cancelButton.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent e) {
                    ContactNameDialog.this.setVisible(false);
                }
            });
        }
        return cancelButton;
    }
  }  
